package com.client.rpcclient;


import com.client.rpcclient.impl.NettyRPCClient;
import com.client.zk.ZkService;
import com.common.loadbalance.LoadBalanceCode;
import com.common.service.DeptService;
import com.common.service.UserService;
import com.common.bean.Dept;
import com.common.bean.User;
import com.common.serialize.impl.KryoSerializer;

/**
 * @author Zixiang Hu
 * @description
 * @create 2021-03-01-15:27
 */
public class NettyClientMain {
    public static void main(String[] args) throws InterruptedException {
        RPCClient client = NettyRPCClient.builder()
                .zkService(new ZkService("192.168.106.130:2181", LoadBalanceCode.CIRCLE.getCode()))
                .serializer(new KryoSerializer())
                .build();
        RPCClientProxy clientProxy = RPCClientProxy.builder().rpcClient(client).build();

        // 测试调用用户服务
        UserService userService = clientProxy.getProxy(UserService.class);
        User user1 = userService.getUserByUserId(1);
        System.out.println("根据用户id查询到的用户是：" + user1);

        User user2 = userService.getUserByUserId(2);
        System.out.println("根据用户id查询到的用户是：" + user2);

//        Integer userId = userService.insertUserId(userByUserId);
//        System.out.println("插入成功，插入id是：" + userId);
        //测试调用部门服务
        DeptService deptService = clientProxy.getProxy(DeptService.class);
        Dept dept1 = deptService.getDeptById(6);
        System.out.println("根据部门id查询到的部门是：" +
                dept1);

        Dept dept2 = deptService.getDeptById(7);
        System.out.println("根据部门id查询到的部门是：" +
                dept2);
//        Integer deptId = deptService.insertDept(deptById);
//        System.out.println("插入成功，插入id是：" + deptId);
    }
}
